package remote.controls
{
	import remote.geom.EdgeMetrics;
	import remote.geom.Size;
	import remote.skins.SolidRectangleSkin;
	import remote.skins.brushes.SolidBrush;
	import remote.utils.DisplayObjectUtil;
	
	/**
	 * 方形进度条
	 * @author 银魂飞雪
	 * @createDate 2011-4-16
	 */
	public class ProgressBar extends ProgressBase
	{
		private var _track:Component;
		private var _bar:Component;
		private var _lb:Label;
		
		
		private var _barEdge:EdgeMetrics;
		public function ProgressBar()
		{
			super();
		}
		/**
		 * @inheritDoc 
		 * 
		 */	
		override protected function initProperty():void
		{
			super.initProperty();
			_width = 150;
			_height = 15;
			_barEdge = new EdgeMetrics(1, 1, 1, 1);
		}
		/**
		 * @inheritDoc 
		 * 
		 */	
		override public function setProgress(value:Number, maxValue:Number):void
		{
			var oldValue:Number = this.value;
			var oldMaxValue:Number = this.maxValue;
			super.setProgress(value, maxValue);
			if(this.value != oldValue || this.maxValue != oldMaxValue)
				updateChildren();
		}
		/**
		 * @inheritDoc 
		 * 
		 */	
		override public function updateSize():void
		{
			var oldSize:Size = new Size(width, height);
			super.updateSize();
			if(!new Size(width, height).equal(oldSize))
			{
				updateChildren();
			}
		}
		/**
		 * @inheritDoc 
		 * 
		 */	
		override protected function createChildren():void
		{
			super.createChildren();
			_track = new Component();
			_track.skin = new SolidRectangleSkin(new SolidBrush(0, 0, 0, 1, 1));
			
			_bar = new Component();
			_bar.skin = new SolidRectangleSkin(new SolidBrush(0x00ff00, 0.7, 0xff0000, 0, 0));
			
			_lb = new Label();
			
	
			addChild(_track);
			addChild(_bar);
			addChild(_lb);
			
		}
		/**
		 * @inheritDoc 
		 * 
		 */	
		override protected function updateChildren():void
		{
			_track.setSize(width, height);
			_bar.move(_barEdge.left, _barEdge.top);
			_bar.setSize(width * value / maxValue - _barEdge.left - _barEdge.right, height - _barEdge.top - _barEdge.bottom);
			_lb.text = Math.round(percent) + "%";
			DisplayObjectUtil.centerX(_lb);
			DisplayObjectUtil.centerY(_lb);
		}
		
		/**
		 * 进度栏和组件四周的距离
		 * <p>大部分情况下，轨道会有边缘；此值设为轨道四周边缘的宽度即可</p>
		 * 
		 */		
		public function get barEdge():EdgeMetrics
		{
			return _barEdge;
		}
		
		public function set barEdge(value:EdgeMetrics):void
		{
			if(!_barEdge.equal(value))
			{
				_barEdge = value;
				updateChildren()
			}
		}

		/**
		 * 进度栏，可使用此属性完全操控进度栏，但是一般情况下，只使用它设置皮肤即可 
		 * 
		 */		
		public function get bar():Component
		{
			return _bar;
		}

		/**
		 * 轨道，一般情况下，只使用它设置皮肤即可
		 * 
		 */		
		public function get track():Component
		{
			return _track;
		}

		
	}
}